/*
 * Copyright (C) 2012 Johan Boris Iantila jiantila@gmail.com && http://www.facebook.com/johanboris.iantila
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package mg.daloji.antandroyd.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

import mg.daloji.antandroyd.CONSTANTS;
import mg.daloji.antandroyd.ImageLoader;
import mg.daloji.antandroyd.R;
import mg.daloji.antandroyd.Radio;
import mg.daloji.antandroyd.application.App;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;




/**
 *
 * @author Johan Boris Iantila
 *
 */
 
public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private LinkedList<Radio> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    
    /*
    public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }
    */
    public LazyAdapter(Activity a, LinkedList<Radio> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView title = (TextView)vi.findViewById(R.id.title); // title
        TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
        TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
        /*
        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);
        */
        
        Radio radio= new Radio();
         radio=data.get(position);
        // Setting all values in listview
        title.setText(radio.getNom());
        artist.setText(radio.getTrigramme());
        duration.setText("direct");
        imageLoader.DisplayImageByResource(radio.getTrigramme(), thumb_image);
     
       
        return vi;
    }
}